package com.sc.study.student.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sc.common.annotation.Log;
import com.sc.common.core.controller.BaseController;
import com.sc.common.core.domain.AjaxResult;
import com.sc.common.enums.BusinessType;
import com.sc.study.student.domain.ScStudentSubject;
import com.sc.study.student.service.IScStudentSubjectService;
import com.sc.common.utils.poi.ExcelUtil;
import com.sc.common.core.page.TableDataInfo;

/**
 * 学员课程Controller
 * 
 * @author sc
 * @date 2022-02-27
 */
@RestController
@RequestMapping("/study/studentsubject")
public class ScStudentSubjectController extends BaseController
{
    @Autowired
    private IScStudentSubjectService scStudentSubjectService;

    /**
     * 查询学员课程列表包含科目和学员
     */
    @PreAuthorize("@ss.hasPermi('study:studentsubject:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScStudentSubject scStudentSubject)
    {
        startPage();
        List<ScStudentSubject> list = scStudentSubjectService.selectScStudentSubjectListIncludeSubjectAndStudent(scStudentSubject);
        return getDataTable(list);
    }

    /**
     * 导出学员课程列表
     */
    @PreAuthorize("@ss.hasPermi('study:studentsubject:export')")
    @Log(title = "学员课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScStudentSubject scStudentSubject)
    {
        List<ScStudentSubject> list = scStudentSubjectService.selectScStudentSubjectList(scStudentSubject);
        ExcelUtil<ScStudentSubject> util = new ExcelUtil<ScStudentSubject>(ScStudentSubject.class);
        util.exportExcel(response, list, "学员课程数据");
    }

    /**
     * 获取学员课程详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:studentsubject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scStudentSubjectService.selectScStudentSubjectById(id));
    }

    /**
     * 新增学员课程
     */
    @PreAuthorize("@ss.hasPermi('study:studentsubject:add')")
    @Log(title = "学员课程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScStudentSubject scStudentSubject)
    {
        return toAjax(scStudentSubjectService.insertScStudentSubject(scStudentSubject));
    }

    /**
     * 修改学员课程
     */
    @PreAuthorize("@ss.hasPermi('study:studentsubject:edit')")
    @Log(title = "学员课程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScStudentSubject scStudentSubject)
    {
        return toAjax(scStudentSubjectService.updateScStudentSubject(scStudentSubject));
    }

    /**
     * 删除学员课程
     */
    @PreAuthorize("@ss.hasPermi('study:studentsubject:remove')")
    @Log(title = "学员课程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scStudentSubjectService.deleteScStudentSubjectByIds(ids));
    }
}
